<template>
	<view class="app-container">
		<u-input placeholder="请输入新密码" v-model="pasw">
			<template slot="suffix">
				<u-icon name="eye"></u-icon>
			</template>
		</u-input>
		<u-input placeholder="请再次输入您的密码" type="password" v-model="password"></u-input>
		<u-button text="完成" shape="circle" type="primary" @click="save" :disabled="disableButton"></u-button>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		modifyPwd
	} from '@/api/api.js'
	export default {
		data() {
			return {
				pasw: '',
				password: '',
				form: {
					phone: '',
					smsCode: ''
				}
			}
		},
		computed: {
			disableButton() {
				if (!this.pasw || !this.password) return true
				return !(this.password === this.pasw)
			}
		},
		onLoad(pageInfo) {
			this.form.phone = pageInfo.phone
			this.form.smsCode = pageInfo.smsCode
		},
		methods: {
			save() {
				modifyPwd({
					...this.form,
					password: this.password
				}).then(res => {
					if (res.code === 10000) {
						this.$refs.uToast.show({
							type: 'success',
							message: "修改成功",
						})
						uni.switchTab({
							url: '/pages/me/me'
						})
					} else {
						this.$refs.uToast.show({
							type: 'error',
							message: res.message,
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss"></style>
